package pl.smath.renderer.model.sign;

import gwt.g2d.client.graphics.Surface;
import gwt.g2d.client.graphics.canvas.Context;
import pl.smath.renderer.utils.Cursor;

public class FactorofSign extends AbstractSign {

	/** Determines whether sign is positive (or negation: "not factor of") */
	private boolean positive;
	private final Double signHeight = 0.7d;
	
	public FactorofSign(boolean positive) {
		super();
		this.positive = positive;
	}

	/**
	 * render the sign on the surface
	 */
	@Override
	public void render(Surface canvas, Cursor cursor) {
		Double x = cursor.getX() + this.getSpace();
		Double y = cursor.getY() - this.getFontHeight()*signHeight;
		Double width = this.getBrushSize();
		Double height = this.getFontHeight()*signHeight;
		canvas.fillRectangle(x, y, width, height);
		if (!positive){
			Context ctx = canvas.getContext();
			ctx.beginPath();
			ctx.moveTo(x - this.getFontHeight()*signHeight/4, y + this.getFontHeight()*signHeight/2 + this.getFontHeight()*signHeight/4);
			ctx.lineTo(x + this.getFontHeight()*signHeight/4, y + this.getFontHeight()*signHeight/2 - this.getFontHeight()*signHeight/4);
			ctx.closePath();
			ctx.stroke();
		}
	}

	/**
	 * update the width and height
	 */
	@Override
	public void update() {
		this.setSignWidth(this.getBrushSize());
		this.setWidth(this.getSignWidth() + this.getSpace()*2);
		this.setHeight(this.getFontHeight());
	}

}
